package com.ly.web.controller.erp;

import java.util.List;

import com.ly.heart.service.ICarCostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ly.common.annotation.Log;
import com.ly.common.core.controller.BaseController;
import com.ly.common.core.domain.AjaxResult;
import com.ly.common.enums.BusinessType;
import com.ly.heart.domain.CarCostEntity;
import com.ly.common.utils.poi.ExcelUtil;
import com.ly.common.core.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 车辆费用单Controller
 *
 * @author cxl
 * @date 2024-09-08
 */
@Api(value = "车辆费用单", tags = "车辆费用单")
@RestController
@RequestMapping("/heart/CarCost")
public class CarCostController extends BaseController {

    @Resource
    private ICarCostService carCostService;

    /**
     * 查询车辆费用单列表
     */
    @PreAuthorize("@ss.hasPermi('heart:CarCost:list')")
    @GetMapping("/list")
    @ApiOperation("查询车辆费用单列表")
    public TableDataInfo list(CarCostEntity carCostEntity)
    {
        startPage();
        List<CarCostEntity> list = carCostService.selectCarCostEntityList(carCostEntity);
        return getDataTable(list);
    }

    /**
     * 导出车辆费用单列表
     */
    @PreAuthorize("@ss.hasPermi('heart:CarCost:export')")
    @Log(title = "车辆费用单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出车辆费用单列表")
    public AjaxResult export(CarCostEntity carCostEntity)
    {
        List<CarCostEntity> list = carCostService.selectCarCostEntityList(carCostEntity);
        ExcelUtil<CarCostEntity> util = new ExcelUtil<CarCostEntity>(CarCostEntity.class);
        return util.exportExcel(list, "CarCost");
    }

    /**
     * 获取车辆费用单详细信息
     */
    @PreAuthorize("@ss.hasPermi('heart:CarCost:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取车辆费用单详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(carCostService.selectCarCostEntityById(id));
    }

    /**
     * 新增车辆费用单
     */
    @PreAuthorize("@ss.hasPermi('heart:CarCost:add')")
    @Log(title = "车辆费用单", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增车辆费用单")
    public AjaxResult add(@RequestBody CarCostEntity carCostEntity)
    {
        return toAjax(carCostService.insertCarCostEntity(carCostEntity));
    }

    /**
     * 修改车辆费用单
     */
    @PreAuthorize("@ss.hasPermi('heart:CarCost:edit')")
    @Log(title = "车辆费用单", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改车辆费用单")
    public AjaxResult edit(@RequestBody CarCostEntity carCostEntity)
    {
        return toAjax(carCostService.updateCarCostEntity(carCostEntity));
    }

    /**
     * 删除车辆费用单
     */
    @PreAuthorize("@ss.hasPermi('heart:CarCost:remove')")
    @Log(title = "车辆费用单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除车辆费用单")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(carCostService.deleteCarCostEntityByIds(ids));
    }
}
